#include "led.h"
#include "key.h"
#include "delay.h"
#include "usart.h"
#include <string.h>

uint8_t buffer[100]            = {0};
uint8_t size                   = 0;
uint8_t receive_one_frame_flag = 0;

// 定义进入睡眠模式的函数
void enter_sleep_mode(void)
{
    // 1. 设置普通睡眠模式（默认）
    SCB->SCR &= ~SCB_SCR_SLEEPDEEP;

    // 2. 使用WFI指令，进入睡眠模式
    __WFI();
}

int main(void)
{
    // 初始化
    USART_Init();

    // 发送单个字符
    USART_SendChar('a');
    USART_SendChar('t');
    USART_SendChar('\n');

    // 发送字符串
    uint8_t *str = "program start!\n";
    USART_SendString(str, strlen((char *)str));

    while(1)
    {
        Delay_s(2);
        str = "would enter low power mode!\n";
        USART_SendString(str, strlen((char *)str));

        // 进入睡眠模式
        enter_sleep_mode();

        str = "exit from low power mode!\n";
        USART_SendString(str, strlen((char *)str));
    }
}
